<template>
	<view >
		<view class='productList' :style="viewColor">
			<view class='search acea-row row-between-wrapper '>

				<view class='input acea-row row-between-wrapper'>
					<!-- <view class="mr-20">		
						<text class="iconfont icon-dingwei mr-5"></text>
						<text>贵阳出发</text>
					</view> -->
					<text class='iconfont icon-ic_search '></text>
				
					<input placeholder='搜索目的地|景点' placeholder-class='placeholder' confirm-type='search' name="search" :value='where.keyword'
					 @confirm="searchSubmit"></input>
				</view>
			</view>
	
			
			<!-- 产品 -->
			<block>
				<view class='list acea-row row-between-wrapper on'>
					<view class='item on' hover-class='none' v-for="(item,index) in productList" :key="index"
					 @click="godDetail(item)">
						<view class='pictrue on'>
							<image :src='item.image'  class="on"></image>
							<view v-if="item.border_pic" :style="{ backgroundImage: `url(${item.border_pic})` }" class="border-picture"></view>
						</view>
						<view class='text on acea-row row-column-between'>
							<view class='name line1'>
								<text class="text_name line2">{{item.store_name}}</text>
							</view>
							<view v-if="item.store_info" class='line1 text-12'>
								<text class="text_name line-ellipsis">
								   <text >{{item.store_info}}</text>
								</text>
							</view>
							<view v-if="item.guarantee_data.length" class="item_tags acea-row line1 mt-10">
								<text class="tags_item labels" v-for="(label,labelIndex) in item.guarantee_data" :key="labelIndex">{{label}}</text>
							</view>
							<!-- <view class="score">{{item.sales}}销量 {{item.reply_count}}条评论</view> -->
							<view class="score">{{item.sales}}销量 </view>
							<view class='money on'>
								<priceFormat class="ml-auto mr-2" :price="item.price" weight intSize="40" floatSize="26" labelSize="26"></priceFormat>
							    <text class="text-10 color-66 mr-10">起</text>
							</view>
						</view>
					</view>
				</view>
			
				<view class='noCommodity' v-if="productList.length==0 && where.page > 1">
					<view class='pictrue' style="margin: 60rpx auto;">
						<image :src="`${domain}/static/images/no_thing.png`"></image>
						<view>暂无产品，去看点什么吧</view>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>

	import {
		getSearchBusListApi,
		getProductHot,
		getBrandlist,
		getStoreTypeApi,
		getParmasList,
		guaranteeListApi
	} from '@/api/store.js';
	import recommend from '@/components/recommend';
	import rightSlider from '@/components/rightSlider.vue'
	import WaterfallsFlow from '@/components/WaterfallsFlow/WaterfallsFlow.vue'
	import {initiateAssistApi} from '@/api/activity.js';
	import { configMap } from "@/utils";
	import util from '@/utils/util.js';
	import productWindow from '@/components/productWindow';
	
	import { mapGetters } from "vuex";
	// #ifndef H5
	import passwordPopup from '@/components/passwordPopup';
	// #endif
	import { goShopDetail } from '@/libs/order.js'
	import { HTTP_REQUEST_URL } from '@/config/app';
	import { toLogin } from '@/libs/login.js';
	const app = getApp();
	export default {
		computed: configMap({hide_mer_status: 1,recommend_switch: 0}, mapGetters(['uid','isLogin','viewColor','keyColor'])),
		components: {
			// #ifndef H5
			passwordPopup,
			// #endif
			recommend,
			rightSlider,
			WaterfallsFlow,
			productWindow,
		},
		watch:{
			
		},
		data() {
			return {
				domain: HTTP_REQUEST_URL,
				productList: [],
				list: [],
				storeTypeArr: [], //店铺类型
				parmasList: [],

				where: {
					cate_pid: '',
					order: '',
					price_on: '',
					price_off: '',
					brand_id: '',
					mer_type_id: '',
					keyword:'',
					is_trader: '',
					filter_params: '',
					page:1,
					limit:20,
					tour_type: 2,
					is_ficti: 4,
					time: '',
					guarantee: '',
					dptDate: '',
					start_city_id: '',
					end_city_id: '',
					start_stop_id: '',
					end_stop_id: '',
					bs_type: 1,
				},
				price: 0,
				stock: 0,
				nows: false,
				loadend: false,
				loading: false,
				loadTitle: '加载更多',
				title: '',
				hostProduct: [],
				hotPage: 1,
				hotLimit: 10,
				hotScroll: false,
				// 筛选框
				rightBox: false,
				brandStataus: false,
				parmasStatus: false,
				//品牌列表
				brandList: [],
				downKey: 0,
				downStatus: false,
				// 下拉菜单
				downMenu: [{
						title: '综合',
						key: 1,
					},
					{
						title: '评分',
						key: 2,
					},
					{
						title: '新品',
						key: 3,
					}
				],
				// 是否第一个
				firstKey:0,
				sotreParam:{
					keyword:'',
					page:1,
					limit:30,
					order:'',
				},
				storeKey:0,
				storeScroll:true,
				activeIndex: 0,
				max_count: 0,
				min_count: 0,
				pay_limit: 1,
				svipData: {},
				svipPrice: false,
				attr: {
					cartAttr: false,
					productAttr: [],
					productSelect: {}
				},
				storeInfo: {},
				cart_num: 1, //购买数量
				isOpen: false, //是否打开属性组件
				selectedArr: [],
				productValue: [], //系统属性
				attrValue: "",
				uniqueValue: "",
				filterData: [],
				defaultSelected: [],
				guaranteeList: [],
				tempdata: [],
				dptDate: '',
				start_city_id: '',
				end_city_id: '',
				start_stop_id: '',
				end_stop_id: '',
			};
		},
		// 滚动监听
		onPageScroll() {
			uni.$emit('scroll');
		},
		onLoad: function(options) {
			
			this.start_city_id = options.start_city_id;
			this.end_city_id = options.end_city_id;
			this.start_stop_id = options.start_stop_id;
			this.end_stop_id = options.end_stop_id;
			this.dptDate = options.date;
			
			
			this.$set(this.where, 'cate_pid', options.id || '');
			this.title = options.title || '';
			this.$set(this.where, 'keyword', options.searchValue || '');
			this.where.start_city_id = options.start_city_id;
			this.where.end_city_id = options.end_city_id;
			this.where.start_stop_id = options.start_stop_id;
			this.where.end_stop_id = options.end_stop_id;
			this.where.date = options.date;
			uni.setNavigationBarTitle({
			　　title:options.origin+'-'+options.destination
			})
			
			this.get_product_list(true);
		},
		onReady(){

		},
		mounted: function() {

		},
		methods: {
			//修改选中项-示例
			changeSelected() {
				//设置选中项
				// 一下的注释是针对测试数据说明结构的意思，具体传入什么数据，要看你自己数据。如果data.js数据有修改，注意defaultSelected也要修改
				//传入defaultSelected的结构不能错，错了就报错运行异常。 不想选中的请传入null
			
				this.defaultSelected = [];
				this.$nextTick(() => {
					this.defaultSelected = [
						[0], //第0个菜单选中 一级菜单的第6项，二级菜单的第0项，三级菜单的第1项
						[],
						[],
						[]
					];
				})

			},
			
			
			getGuaranteeList(){
				let temp = []
			
				guaranteeListApi()
					.then(res => {
						// this.guaranteeList = res.data;
						var submenu = [];
						for(var i = 0; i < res.data.length;i++){
							submenu.push({
								"name": res.data[i].guarantee_name,
								"value": res.data[i].guarantee_id
							})
						}
						// this.tempdata.push({
						// 	name:'筛选',
						// 	"type": 'filter',
						// 	"submenu": [{
						// 			"name": "服务保障",
						// 			"submenu": submenu 
						// 		}]
						// })
						var fl = {
							name:'筛选',
							"type": 'filter',
							"submenu": [{
									"name": "服务保障",
									"submenu": submenu 
								}]
						};
							this.filterData = this.tempdata.concat(fl);
						console.log('this.filterData',this.filterData)
					})
					.catch(res => {
						this.$util.Tips({
							title: res
						});
					});
			},
			
			// 去店铺
			goShop(id){
				if(this.hide_mer_status != 1){
					uni.navigateTo({
						url:`/pages/store/home/index?id=${id}`
					})
				}
			},
			// 获取店铺类型
			async getStoreType() {
				let temp = []
				getStoreTypeApi()
					.then(res => {
						temp = res.data.map(item => {
							return {
								...item,
								check: false
							}
						})
						this.storeTypeArr = temp
					})
					.catch(res => {
						this.$util.Tips({
							title: res
						});
					});
			},
			// 获取参数列表
			async getParmasList(){
				let temp = []
				getParmasList({
					cate_pid:this.where.cate_pid,
					keyword:this.where.keyword
				})
					.then(res => {
						this.parmasStatus = true
						temp = res.data.map(item => {
							return {
								...item,
								check: false,
								showValue: false,
								parmasValue: []
							}
						})
						this.parmasList = temp
					})
					.catch(res => {
						this.$util.Tips({
							title: res
						});
					});
			},
			// 右侧切换
			bindRight(){
				this.price = 0;
				this.firstKey = 4;
				if(!this.brandList.length)this.getBrandlist()
				if(!this.storeTypeArr.length)this.getStoreType()
				if(!this.parmasList.length)this.getParmasList()
				this.rightBox = true
			},
			// 品牌列表
			async getBrandlist(){
				let temp = []
				getBrandlist({
					cate_pid:this.where.cate_pid,
					keyword:this.where.keyword
				}).then(res=>{
					this.brandStataus = true
					temp = res.data.list.map(item=>{
						return {
							...item,
							check:false
						}
					})
					this.brandList = temp
				})
			},
			// 去详情页
			godDetail(item) {
				if (this.isLogin) {
					goShopDetail(item, this.$store.state.app.uid).catch(res => {
					
					});
					// uni.navigateTo({
					// 	url: `/pages/product/details/index?id=${item.product_id}`
					// })	
					
				} else {
					toLogin()
				}
				
			},
			
			// 组件关闭
			close() {
				this.rightBox = false
			},
			
			
			searchSubmit: function(e) {
				let that = this;
				that.$set(that.where, 'keyword', e.detail.value);
				that.loadend = false;
				that.$set(that.where, 'page', 1)
				this.get_product_list(true);
			},
		
			//查找产品
			get_product_list: function(isPage) {
				let that = this;
				if (that.loadend) return;
				if (isPage === true) that.$set(that, 'productList', []);
				that.loading = true;
				that.loadTitle = '';
				getSearchBusListApi(that.where).then(res => {
					let list = res.data.list;
					let productList = that.$util.SplitArray(list, that.productList);
					let loadend = list.length < that.where.limit;
					that.loadend = loadend;
					that.loading = false;
					that.loadTitle = loadend ? '已全部加载' : '加载更多';
					that.$set(that, 'productList', productList);
					that.$set(that.where, 'page', that.where.page + 1);
				}).catch(err => {
					that.loading = false;
					that.loadTitle = '加载更多';
				});
			},
		
		},	
		onPullDownRefresh() {

		},
		onReachBottom() {
			if (this.productList.length > 0) {
				this.get_product_list('');
			} 
		},
		onPullDownRefresh(){
			// 模拟上拉刷新
			setTimeout(()=>{
				const newList = this.productList.reverse();
				this.productList = newList;
				uni.stopPullDownRefresh();
			},500)
		}

	}
</script>
<style lang="scss" scoped>
	.productList .search {
		width: 100%;
		height: 86rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		// position: fixed;
		left: 0;
		top: 0;
		z-index: 150;
		 // background-image: linear-gradient(rgb(220, 228, 235), rgb(217, 225, 231));
		 background-color: #FFF;
	}
	.bt-color{
		background-color: var(--view-theme);
		border:1px solid var(--view-theme);
		&.type2{
			background-color: #FD6523;
			border: 1px solid #FD6523;
		}
	}
	.productList .search .back {
		display: flex;
		align-items: center;
		width: 40rpx;
		height: 60rpx;
		.iconfont {
			color: #fff;
			font-size: 36rpx;
		}
	}
	.productList .search .input {
		/* #ifdef MP || APP-PLUS */
		width: 650rpx;
		/* #endif */
		/* #ifndef MP || APP-PLUS */
		width: 600rpx;
		/* #endif */
		height: 60rpx;
		background-color: #ececec;
		border-radius: 50rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
	}
	.productList .search .input input {
		flex: 1;
		// height: 100%;
		font-size: 26rpx;
		margin-left: 10rpx;
		background-color: #ececec;
	}
	.productList .search .input .placeholder {
		color: #999;
	}
	.productList .search .input .iconfont {
		font-size: 26rpx;
		color: #555;
	}
	.productList .search .icon-a-ic_Imageandtextsorting,
	.productList .search .icon-a-ic_Picturearrangement {
		color: #fff;
		width: 62rpx;
		font-size: 40rpx;
		height: 86rpx;
		line-height: 86rpx;
	}
	.productList .nav-wrapper {
		// z-index: 9;
		// position: fixed;
		// left: 0;
		// top: 0;
		// width: 100%;
		// margin-top: 86rpx;
		// background-color: rgb(217, 225, 231);
		.tab-bar {
			display: flex;
			align-items: center;
			.tab-item {
				position: relative;
				flex: 1;
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 8rpx 0 20rpx;
				color: #fff;
				font-size: 28rpx;
				font-weight: bold;
				&::after {
					content: ' ';
					position: absolute;
					left: 50%;
					bottom: 18rpx;
					width: 30rpx;
					height: 3rpx;
					background: transparent;
					transform: translateX(-50%);
				}
				&.on {
					&::after {
						background: #fff;
					}
				}
			}
		}
	}
	.productList .nav {
		height: 86rpx;
		color: #454545;
		font-size: 28rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		padding: 0 28rpx;
		border-radius: 24rpx 24rpx 0 0;
	}
	.productList .nav .item {
		display: flex;
		align-items: center;
		justify-content: center;
		flex: 1;
		&.t-color{
			font-weight: bold;
		}
	}
	.productList .nav .item image {
		width: 15rpx;
		height: 19rpx;
		margin-left: 10rpx;
	}
	.productList{
		padding-bottom: calc(0rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
		padding-bottom: calc(0rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
	}
	.productList .list {
		padding: 0 20rpx;
		// margin-top: 168rpx;
	}
	.productList .list.on {
		background-color: #fff;
		border-top: 1px solid #f6f6f6;
		padding-top: 24rpx;
	}
	.icon-ic_right {
		margin-top: 6rpx;
	}
	.icon-ic_sort {
		font-size: 30rpx;
		margin-left: 10rpx;
	}
	.down-wrapper {
		.bg {
			z-index: 8;
			position: fixed;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			background: rgba(0, 0, 0, .5);
		}
		.down-box {
			z-index: 8;
			position: fixed;
			left: 0;
			top: 170rpx;
			width: 100%;
			padding: 0 40rpx 28rpx 74rpx;
			background-color: #F8F8F8;
			border-radius: 0 0 24rpx 24rpx;
			.down-item {
				margin-top: 28rpx;
				font-size: 24rpx;
				color: #454545;
				&.on {
					color: var(--view-theme);
				}
				.iconfont{
					float: right;
				}
			}
		}
	}
	.productList .list .item.on {
		width: 100%;
		display: flex;
		justify-content: space-between;
		margin-bottom: 32rpx;
		position: relative;
		margin-right: 10px;
	}
	.productList .list .item .pictrue.on {
		position: relative;
		width: 220rpx;
		// height: 250rpx;
		// min-height: 200px;
		max-height: 250px;
		.border-picture {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background: center/cover no-repeat;
			border-radius: 16rpx;
		}
	}
	.productList .list .item .pictrue image {
		width: 220rpx;
		// height: 240rpx;
		// min-height: 200px;
		// max-height: 250px;
		border-radius: 20rpx 20rpx 0 0;
	}
	.productList .list .item .pictrue image.on {
		border-radius: 16rpx;
		width: 220rpx;
		// height: 100%;
		height: 220rpx;
		// height: 250rpx;
	}
	.productList .list .item .text {
		font-size: 30rpx;
		color: #222;
		width: 460rpx;
		padding: 0 0 0 22rpx;
		.name{
			font-size:30rpx;
			font-weight: 700;
			margin-bottom: 5px;
		}
	}
	.productList .list .item .text.on {
		padding: 8rpx 0 0;
		// width: 420rpx;
		margin-left: 12px;
		// height: 250rpx;
	}
.item_tags{
	margin-top: 8px;
}
.item_tags .tags_item {
	display: inline-block;
	font-size: 20rpx;
	text-align: center;
	border-radius: 5rpx;
	padding: 0 4rpx;
	line-height: 28rpx;
	margin-right: 8rpx;
}
.item_tags .tags_item.ticket{
	color: #E93323;
	border: 1px solid #E93323;
}
.item_tags .tags_item.delivery{
	color: #FF9000;
	border: 1px solid #FF9000;
}
.item_tags .tags_item.labels{
	color: var(--view-theme);;
	border: 1px solid #cad8f7;
}
	.productList .list .item .text .money {
		display: flex;
		align-items: flex-end;
		font-size: 26rpx;
		font-weight: bold;
		margin-top: 10rpx;
		color: var(--view-priceColor);
	}
	.productList .list .item .text .money .num {
		font-size: 34rpx;
	}
	.productList .distance {
		display: flex;
		align-items: center;
		font-size: 24rpx;
		color: #999999;
		.icon-ic_right {
			font-size: 24rpx;
			line-height: 24rpx;
		}
	}
	.productList .list .item .text .money .ticket-big {
		display: flex;
		align-items: center;
		justify-content: center;
		min-width: 163rpx;
		height: 28rpx;
		margin-left: 10rpx;
		background-image: url(~static/images/yh.png);
		background-size: 100% 100%;
		font-size: 20rpx;
		font-weight: normal;
		padding: 0 10rpx;
	}
	.productList .list .item .text .score {
		margin-top: 10rpx;
		color: #737373;
		font-size: 22rpx;
	}
	.productList .list .item .text .company {
		display: flex;
		align-items: center;
		color: #737373;
		font-size: 22rpx;
		margin-top: 6rpx;
		.name {
			display: inline-block;
			width: 200rpx;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}
		.flex {
			display: flex;
			align-items: center;
			margin-left: 10rpx;
			color: #282828;
			.iconfont {
				font-size: 20rpx;
				margin-top: 4rpx;
			}
		}
	}
	.productList .list .item .foot-bar {
		width: 100%;
		height: 52rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-image: linear-gradient(-90deg, var(--view-bntColor21) 0%, var(--view-bntColor22) 100%);
		border-radius: 0px 0px 16rpx 16rpx;
		color: #fff;
		font-size: 24rpx;
		.icon-fenxiang {
			font-size: 24rpx;
			margin-right: 10rpx;
		}
		&.on {
			position: absolute;
			right: 0;
			bottom: 30rpx;
			width: 180rpx;
			height: 44rpx;
			border-radius: 22rpx;
		}
	}
</style>
